<?php
if (!is_object(cmsms())) exit;
#if (!$this->CheckPermission('Manage Counters')) exit;
$img_true = "<img src='" . $config["root_url"] . '/modules/' . $this->getName() . "/img/true.gif' alt='true'/>";
$img_false = "<img src='" . $config["root_url"] . '/modules/' . $this->getName() . "/img/false.gif' alt='false'/>";
$img_delete = "<img src='" . $config["root_url"] . '/modules/' . $this->getName() . "/img/delete.gif' alt='delete'/>";
$img_error = $config["root_url"] . '/modules/' . $this->getName() . '/img/block.png';

$db = cmsms()->GetDb();

$result = array();
$Counters = array();

$query = "SELECT * FROM " . cms_db_prefix() . "module_counters ORDER BY cntr_id DESC";
$dbresult = $db->Execute($query);

while ($dbresult && $row = $dbresult->FetchRow())
{
    $cntr = new stdClass();
    $cntr->id = $row['cntr_id'];     
    $cntr->name = $row['name'];     
    $cntr->description = $row['description'];     
    $cntr->explanation = $row['explanationd'];     
    $cntr->value = $row['value'];     
    $cntr->ceiling = $row['ceiling'];     
    $cntr->product_id = $row['product_id'];     
    
    $cntr->usage = "{" . $this->GetName() . " name='" . $cntr->name . "' ceiling='c' value='v'}";     
    
    #$cntr->link = $cntr->name = $this->CreateLink($id, 'admin_counter_addedit', $returnid, $cntr->name, array('nid'=>$cntr->id));
    $cntr->link = $this->CreateLink($id, 'admin_counter_addedit', $returnid, $cntr->name, array('cntr_id'=>$cntr->id));
    $cntr->resetlink = $this->CreateLink($id, 'admin_counter_reset', $returnid, cmsms()->get_variable('admintheme')->DisplayImage('icons/system/back.gif', $this->Lang('reset'),'','','systemicon'), array('cntr_id'=>$cntr->id), $this->Lang('are_you_sure'));
    $cntr->editlink = $this->CreateLink($id, 'admin_counter_addedit', $returnid, cmsms()->get_variable('admintheme')->DisplayImage('icons/system/edit.gif', $this->Lang('edit'),'','','systemicon'), array('cntr_id'=>$cntr->id));
    $cntr->deletelink = $this->CreateLink($id, 'admin_counter_delete', $returnid, cmsms()->get_variable('admintheme')->DisplayImage('icons/system/delete.gif', $this->Lang('delete'),'','','systemicon'), array('cntr_id'=>$cntr->id), $this->Lang('are_you_sure'));         

    $Counters[] = $cntr;
}

# send everything to Smarty
$smarty->assign('counters',$Counters);

$smarty->assign('add_counter', $this->CreateLink($id, 'admin_counter_addedit', $returnid, cmsms()->get_variable('admintheme')->DisplayImage('icons/system/newobject.gif',$this->Lang('add_counter'),'','','systemicon'),array(), '', false) . 
                                $this->CreateLink($id, 'admin_counter_addedit', $returnid,$this->Lang('add_counter'),array(), '', false));



?>
